//
//  AddCarTCell.swift
//  MikerShop
//
//  Created by eme on 2016/12/9.
//  Copyright © 2016年 eme. All rights reserved.
//

/*
 owner:cy
 update:2016年12月09日14:48:03
 info:添加购物车的 基础cell
 VC :  HomePageVc
 */
import UIKit
import Kingfisher
import RxSwift
import RickonCore
import CommonCore

class AddCarTCell: UITableViewCell {
    private let disposeBag = DisposeBag()
    
    @IBOutlet weak var seperateLine_V: UIView!
    /// 规格名称
    @IBOutlet weak var skuname_Lb: UILabel!
    //价格
    @IBOutlet weak var price_Lb: UILabel!
    //起订量
    @IBOutlet weak var moq_Lb: UILabel!
    /// 库存
    @IBOutlet weak var stock_Lb: UILabel!
    /// 编辑商品数量
    @IBOutlet weak var editnum_CnV: ChangeNumView!
    var didUpdate_Closure:((_ item:SkusModel) -> Void)?
    
    var item:SkusModel? {
        didSet {
            if let item = self.item {
                print(item.skuname)
                self.skuname_Lb.text = item.skuname
                self.price_Lb.text = item.price.getPriceStr()
                self.moq_Lb.text = "起批量:\(item.edit_moq)\(item.unit)"
                self.stock_Lb.text = "库存:\(item.stock)"
                self.editnum_CnV.mod = item.edit_moq
                self.editnum_CnV.stock = item.stock
                self.editnum_CnV.cartNumber = item.editnum
            }
        }
    }
    
    
    override func awakeFromNib() {
        
        self.seperateLine_V.backgroundColor = Theme.v.bg_color
        /// 修改model中的数量
        self.editnum_CnV.editnumSubject.asObserver().subscribe(onNext: {[unowned self] (productNum) in
            self.item?.editnum = productNum
            if let didUpdate_Closure = self.didUpdate_Closure{
                if let item = self.item{
                    didUpdate_Closure(item)
                }
            }
        }).disposed(by: disposeBag)
        
        
        
    }
}
